<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
 * 系统菜单
 */
class CreateSysMenuTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //菜单分组表
        Schema::create('sys_menu_groups', function (Blueprint $table) {
            $table->increments('group_id')->comment('菜单分组ID');
            $table->string('group_key', 10)->unique()->default('')->comment('分组键名');
            $table->string('group_name', 50)->default('')->comment('分组名称');
            $table->softDeletes();
            $table->timestamps();
        });
        //菜单表
        Schema::create('sys_menus', function (Blueprint $table) {
            $table->increments('menu_id')->comment('菜单ID');
            $table->unsignedInteger('group_id')->default(0)->comment('分组ID');
            $table->string('menu_name', 50)->defalult('')->comment('菜单名称');
            //权限ID，用于生成url
            $table->unsignedInteger('perm_id')->default(0)->comment('权限ID');
            $table->string('route_params', 200)->default('')->comment('路由参数');
            $table->string('icon_class', 50)->default('')->comment('图标样式');
            $table->unsignedInteger('parent_id')->default(0)->comment('父级ID');
            $table->text('description')->comment('菜单描述');
            $table->smallInteger('order_num')->default(0)->comment('排序数字，值越小越靠前');
            //外键
            $table->foreign('group_id')
                ->references('group_id')
                ->on('sys_menu_groups')
                ->onDelete('cascade');

            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('sys_menus');
        Schema::dropIfExists('sys_menu_groups');
    }
}
